package cn.bon.schedule.service.impl;

import cn.bon.schedule.api.pojo.dto.RealTimeScheduleDTO;
import cn.bon.schedule.api.pojo.po.RealTimeSchedule;
import cn.bon.schedule.api.pojo.po.ScheduDetail;
import cn.bon.schedule.mapper.RealTimeScheduleMapper;
import cn.bon.schedule.service.RealTimeScheduleService;
import cn.bon.schedule.service.ScheduDetailService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 实时排班 服务实现类
 * </p>
 *
 * @author LuoChao
 * @since 2024-01-15
 */
@Service
public class RealTimeScheduleServiceImpl extends ServiceImpl<RealTimeScheduleMapper, RealTimeSchedule> implements RealTimeScheduleService {
    @Resource
    ScheduDetailService scheduDetailService;

    /**
     * 添加实时排班
     * @param realTimeScheduleDTOS 实时排班DTO
     * @param scheduleId 排班方案id
     */
    @Override
    public void add(RealTimeScheduleDTO[] realTimeScheduleDTOS, Long scheduleId) {

        //遍历每一个实时排班项，保存
        for (RealTimeScheduleDTO realTimeScheduleDTO : realTimeScheduleDTOS) {
            RealTimeSchedule realTimeSchedule = new RealTimeSchedule();
            BeanUtil.copyProperties(realTimeScheduleDTO, realTimeSchedule);
            realTimeSchedule.setScheduPlanId(scheduleId);

            //保存每个实时排班
            this.save(realTimeSchedule);


            Long comId = realTimeScheduleDTO.getComId();
            ScheduDetail[] scheduDetails = realTimeScheduleDTO.getScheduDetails();
            //添加排班每日详情
            scheduDetailService.add(scheduDetails, comId);
        }

    }


    /**
     * 刷新冲突信息
     * @param scheduPlanId
     */
    @Override
    public void refresh(Long scheduPlanId) {
        //1.计算已发生工时
        //2.计算已排班工时
        //3.排班冲突检测
        //4.排班规则检测
    }
}
